package cn.dxs.gitee.http.error;

import android.support.annotation.StringRes;

import java.util.HashMap;
import java.util.Map;

import cn.dxs.gitee.App;
import cn.dxs.gitee.R;

/**
 * 网络请求错误码(根据错误码获取错误msg)
 *
 * @author lijian
 * @date 2019-09-21 16:23
 */
public class HttpErrorCode {

    /**网络和缓存不可用*/
    public static final int NO_CACHE_AND_NETWORK = 0;
    /**页面不存在*/
    public static final int PAGE_NOT_FOUND = 1;
    /**未授权*/
    public static final int UNAUTHORIZED = 2;

    private final static Map<Integer, String> ERROR_MSG_MAP = new HashMap<>();

    static {
        ERROR_MSG_MAP.put(NO_CACHE_AND_NETWORK, getString(R.string.no_cache_and_network));
        ERROR_MSG_MAP.put(PAGE_NOT_FOUND, getString(R.string.page_no_found));
        ERROR_MSG_MAP.put(UNAUTHORIZED, getString(R.string.unauthorized));
    }

    public static String getErrorMsg(int errorCode) {
        return ERROR_MSG_MAP.get(errorCode);
    }

    private static String getString(@StringRes int resId) {
        return App.getContext().getResources().getString(resId);
    }
}
